﻿Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Namespace Users
    Public Structure User
        Dim nick As String
        Dim mode As ChatEngine.Connections.ModeEnum
    End Structure
    <Serializable()> _
    Public Class UserList
        Inherits CollectionBase
        Dim Stuff As Integer
        Default Public Property Item(ByVal index As Integer) As User
            Get
                Return CType(List(index), User)
            End Get
            Set(ByVal Value As User)
                List(index) = Value
            End Set
        End Property
        Public Function Add(ByVal value As User) As Integer
            Return List.Add(value)
        End Function
        Public Function IndexOf(ByVal value As User) As Integer
            Return List.IndexOf(value)
        End Function
        Public Sub Insert(ByVal index As Integer, ByVal value As User)
            List.Insert(index, value)
        End Sub
        Public Sub Remove(ByVal ItemTitle As String)
            Dim Usr = From usrvar As User In Me.List Where usrvar.nick = ItemTitle
            Me.Remove(Usr(0))
        End Sub
        Public Sub Remove(ByVal value As User)
            List.Remove(value)
        End Sub
        Public Function Contains(ByVal value As User) As Boolean
            Return List.Contains(value)
        End Function
        Public Property GetItemCount() As Integer
            Get
                Return Stuff
            End Get
            Set(ByVal Value As Integer)
                Stuff = Value
            End Set
        End Property
        Public Sub EditItem(ByVal item As User, ByVal PropToChange As String, Optional ByVal Value As Object = Nothing, Optional ByVal Mode As Connections.ModeEnum = Nothing)
            Dim Usr = From usrvar As User In Me.List Where usrvar.nick = item.nick
            Dim newusr As User = New User
            Select Case PropToChange
                Case "Mode"
                    newusr.nick = Usr(0).nick
                    newusr.mode = Mode
                    Me.Remove(Usr(0))
                    Me.Add(newusr)
                Case "Nick"
                    newusr.nick = CType(Value, Connections.ModeEnum)
                    newusr.mode = Usr(0).mode
                    Me.Remove(Usr(0))
                    Me.Add(newusr)
            End Select
        End Sub
        Function Find(ByVal itemTitle As String) As User
            Try
                Dim ItemReturn As New User
                Dim Item As New User
                For Each Item In Me.List
                    Dim A As String = Item.nick
                    If LCase(Item.nick) = LCase(itemTitle) Then
                        ItemReturn = Item
                        Return ItemReturn
                        Exit For
                    End If
                Next
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return Nothing
        End Function
    End Class
End Namespace
